package org.zpmis.domain.customer.vo;

import lombok.Data;
import org.zpmis.domain.customer.model.ReturnVisit;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

@Data
public class GetVisitDetailVo {
    private Long id;

    /**
     * 意向表id
     */
    private Long intentionId;

    /**
     * 跟进人id
     */
    private Long chargePersonId;

    /**
     * 负责人、跟进人
     */
    private String chargePerson;

    /**
     * 回访日志
     */
    private String visitLog;

    /**
     * 企业名称
     */
    private String companyName;

    /**
     * 联系人
     */
    private String contactPerson;

    /**
     * 联系手机号
     */
    private String contactMobile;

    /**
     * 跟进结果 1无效客户2有效客户，3继续跟进
     */
    private Integer visitResult;

    /**
     * 结果描述
     */
    private String resultDesc;

    /**
     * 跟进计划
     */
    private String followPlan;

    /**
     * 回访方式 1电话2线下约谈
     */
    private Integer visitType;

    /**
     * 回访日期
     */
    private String visitTime;

    /**
     * 下次回访日期
     */
    private String visitNextTime;

    /**
     * 是否删除 0否1是
     */
    private Integer isDeleted;

    /**
     * 回访状态 1进行中2已完结
     */
    private Integer status;

    /**
     * 是否提醒 0否1是
     */
    private Integer isRemind;

    /**
     * 创建人id
     */
    private Long createId;

    /**
     * 创建人
     */
    private String createPerson;

    /**
     * 创建时间
     */
    private String createTime;

    /**
     * 备注
     */
    private String remake;

    public static GetVisitDetailVo toVisitDetailVo(ReturnVisit returnVisit) {
        if (returnVisit == null){
            return null;
        }
        GetVisitDetailVo visitDetailVo = new GetVisitDetailVo();
        visitDetailVo.setId(returnVisit.getId());
        visitDetailVo.setIntentionId(returnVisit.getIntentionId());
        visitDetailVo.setChargePersonId(returnVisit.getChargePersonId());
        visitDetailVo.setChargePerson(returnVisit.getChargePerson());
        visitDetailVo.setVisitLog(returnVisit.getVisitLog());
        visitDetailVo.setCompanyName(returnVisit.getCompanyName());
        visitDetailVo.setContactPerson(returnVisit.getContactPerson());
        visitDetailVo.setContactMobile(returnVisit.getContactMobile());
        visitDetailVo.setVisitResult(returnVisit.getVisitResult());
        visitDetailVo.setResultDesc(returnVisit.getResultDesc());
        visitDetailVo.setFollowPlan(returnVisit.getFollowPlan());
        visitDetailVo.setVisitType(returnVisit.getVisitType());
        visitDetailVo.setVisitTime(returnVisit.getVisitTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(returnVisit.getVisitTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        visitDetailVo.setVisitNextTime(returnVisit.getVisitNextTime() == null ? "" : LocalDateTime.ofInstant(Instant.ofEpochMilli(returnVisit.getVisitNextTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        visitDetailVo.setIsDeleted(returnVisit.getIsDeleted());
        visitDetailVo.setStatus(returnVisit.getStatus());
        visitDetailVo.setIsRemind(returnVisit.getIsRemind());
        visitDetailVo.setCreateId(returnVisit.getCreateId());
        visitDetailVo.setCreatePerson(returnVisit.getCreatePerson());
        visitDetailVo.setCreateTime(LocalDateTime.ofInstant(Instant.ofEpochMilli(returnVisit.getCreateTime()), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        visitDetailVo.setRemake(returnVisit.getRemake());
        return visitDetailVo;
    }
}
